package com.smartplatform.utils;

import com.smartplatform.pojo.MyBaseUser;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @Author 咕唧
 * @Date 2022/5/30 15:58
 * @Version 1.0
 */
public class SecurityUtils {
    public static MyBaseUser getUserInfo(boolean test) {

        if (test) {
            MyBaseUser baseUser = new MyBaseUser("ceshizhanghao", "", null);
            baseUser.setUserId(-1L);
            return baseUser;
        }
        //因为现在登录交给了security,数据也放到了scurity中,所以用户的数据就从security中获取
        MyBaseUser baseUser = (MyBaseUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
//        return (SysUserInfo) ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession().getAttribute("user");
        return baseUser;
    }
}
